home *** CD-ROM | disk | FTP | other *** search
- Path: fig.leba.net!not-for-mail
- From: fweaver@leba.net
- Newsgroups: comp.lang.c
- Subject: fopen not working
- Date: 10 Feb 1996 22:25:21 -0500
- Organization: LebaNet, Lebanon PA
- Sender: fweaver@fig.leba.net
- Message-ID: <4fjnj1$4q@fig.leba.net>
- NNTP-Posting-Host: fig.leba.net
-
- Good evening to all C programers
-
- I have a problem I thought someone might be able to shed some light on
- for me. Below is some of the code I wrote for an install program.
-
-
- #include<stdio.h>
- #include<conio.h>
- char buf[125],stwd[110],trwd[110],*pt,*pt1;
- int i,vr,vd;
- FILE *in, *out;
- main()
- { [snip]
-
- instlfile("trkr.cf_","trkr.cfg");
- instlfile("maplvl3.da_","maplvl3.dat");
- instlfile("atpctrkr.do_","atpctrkr.doc");
- instlfile("readme.1s_","readme.1st");
- instlfile("file_id.di_","file_id.diz");
-
- [snip]
-
- if((in=fopen(buf,"r"))!=NULL)
- { do{ fgets(buf,120,in);
- pt= (char *)strstr(buf,"XXXXX");
- if(pt!=NULL){ fclose(out); pt=pt+5;if((out=fopen(pt,"w"))==NULL)printf("ERROR");
- else{printf("\nInstalling %s",pt);continue; }}
- fputs(buf,out);
- }while(feof(in)==0);
- }
- }
- What I am trying to do here is seperate one text file (in) back into
- individual files (out). Each file within the first file, starts with a line
- beginning XXXXX. Immediately following (on the same line) is the file name
- for the following lines of text. When XXXXX is found the old out file is to be
- closed and a new one fopened. That is not happenning. Pointer pt is pointing
- at the correct data, because if I printf("%s",pt); instead printf("ERROR");
- it prints the correct file name. File pointer out is still NULL, though after
- fopen. The function below works just fine. Any Ideas welcome. Thanks
-
- Floyd Weaver
-
- Internet E-Mail fweaver@leba.net
- Home page http://www.leba.net/~fweaver
-
- [snip]
-
- instlfile(char f[15],char s[15])
- { sprintf(buf,"%s%s",stwd,f);
- if((in=fopen(buf,"rb"))==NULL){close(in);return(0);}
- if((out=fopen(s,"wb"))!=NULL)printf("\nInstalling %s",s);
- while((i=fgetc(in))!=EOF){fputc(i,out);}
- _fcloseall();
- }
-